package org.example.leetCode;

import java.util.Arrays;

/**
 * @author Administrator
 */
public class moveZero {
    public static void main(String[] args) {
        int[] nums ={0,0,1};
        moveZeros2(nums);
        System.out.println(Arrays.toString(nums));
    }

    public static void moveZeros1(int[] nums) {
        int count =0;
        for(int i =0;i< nums.length-count-1;){
            if (nums[i]==0){
                for(int j = i;j< nums.length-count-1;j++){
                    int temp = nums[j];
                    nums[j]=nums[j+1];
                    nums[j+1]=temp;
                }
                count++;
            }else {
                i++;
            }
        }
    }

    public static void moveZeros2(int[] nums){
        if (nums==null || nums.length<=1){
            return;
        }
        int index = 0;
        for (int i =0;i< nums.length;i++){
            if (nums[i]!=0){
                nums[index] = nums[i];
                index++;
            }
        }
        for (int j=index;j< nums.length;j++){
            nums[j]=0;
        }
    }
}
